package com.apple;

import com.apple.service.BufferRead;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

@Slf4j
@Component
@RequiredArgsConstructor
public class SocketServer {
    private final BufferRead bufferRead;

    @PostConstruct
    public void receive(){
        try(ServerSocket serverSocket=new ServerSocket(8081)){
            log.info("[socket服务端]->启动成功");
            while(true){
                Socket socket=serverSocket.accept();
                bufferRead.read(socket);
                Thread.sleep(500);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
